<?php
    session_start();
    require_once 'php/database.php';
    require_once 'php/photo.php';

    function curPageURL() {
         $pageURL = 'http';
         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
         $pageURL .= "://";
         if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
         } else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
         }
         return $pageURL;
    }

    function getUserNamePage(){
        if (isset($_SESSION['username']))
	{
		$login = true;
	}
	else{
		$login = false;
		//header("Location: ".$CFG->url."home.php");
	}
	$loguname = $_SESSION['username'];
	$username = $_GET["un"];
	if ($username==NULL&&$login){
		$username=$loguname;
	}
        return $username;
    }
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style/footoo.css" />
    <link rel="stylesheet" type="text/css" href="style/ftheader.css" />
    <link rel="stylesheet" type="text/css" href="style/ftfooter.css" />
    <link rel="stylesheet" type="text/css" href="style/ftcommoncontent.css" />
    <link rel="stylesheet" type="text/css" href="style/ftprofmes.css" />
    <link rel="icon" href="images/footoologomini.png" type="image/png" />
    <script type="text/javascript" src="script/editprofile.js"></script>
    <script type="text/javascript" src="script/datetimepicker.js"></script>
    <script type="text/javascript">
        function submiteditform(){
            document.forms["editprofile"].submit();
        }

        function backToProfile(user){
            var xmlhttp;
            if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else{// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function(){
                if (xmlhttp.readyState==4 && xmlhttp.status==200){
                    document.getElementById("profilecontentajax1").innerHTML= xmlhttp.responseText;
                }
            }

            xmlhttp.open("GET","profile4.php?un="+user,true);
            xmlhttp.send();
        }
    </script>
    <title>Edit Profile</title>
</head>

<body>
    <div id="headerwrapper">
	<div id = "headerbgfx"></div>
        <div id="footooheader">
            <div id="footoologo">
            	<a href="#"></a>
            </div>
            <div id="loginarea">
                <a href = "php/logout.php">Signout</a>;
            </div>
        </div>
        <div id="footoomenu">
            <ul>
                <li>
                    <a href="home.php">Home</a>
                </li>
                <li>
                    <?php
                        echo '<a href="profile.php?un='.$_SESSION['username'].'" class="current">Profile</a>';
                    ?>
                </li>
                <li>
                    <?php
                        echo '<a href="wall.php?'.$_SESSION['username'].'" >Wall</a>';
                    ?>
                </li>
                <li>
                    <?php
                        echo '<a href="fts.php >Photos</a>';
                    ?>
                </li>
                <li>
                    <?php
                        echo '<a href="message.php?un='.$_SESSION['username'].'" >Message</a>';
                    ?>
                </li>
            </ul>
        </div>
    </div>
    <div id="headermirror">
    	<div id="searchbox">
            <form action="search.php" method="post">
            	<select class="searchselect" name="tipe">
                	<option value="user">User</option>
                	<option value="photo">Photo</option>
                </select>
                <div class="searchbutton">
                    <input id="searchbutton" type="submit" value="" />
                </div>
                <div class="searchtext">
                <input id="searchtext" class="searchtext" type="text" name="searchtext" value="search" onfocus="filledTrue(this.id, 'search')" onblur="filledFalse(this.id, 'search')" />
            	</div>
            </form>
        </div>
    </div>
    <div id="contentwrapper">
        <div id="profilecontentajax1">
            <form action="php/editprofile.php?un=<?php $usr = getUserNamePage(); echo $usr; ?>" method="post" name="editprofile" id="editprofile">
            <input type="hidden" value="editprofile" name="operation"/>

                <div id="editform" class="boxy">
                        <p class="judul">Edit your profile below.</p>
                        <?php
                            $pemilik = $_SESSION['username'];
                            $con = mysql_connect("localhost", "progin", "progin");
                            if (!$con)
                                    die('Could not connect: ' . mysql_error());

                            mysql_select_db("progin", $con);

                            $hasil = mysql_query("SELECT * FROM user WHERE Username = '$pemilik'", $con);
                            $count = 0;
                            if(mysql_num_rows($hasil)>0){
                                $baris = mysql_fetch_row($hasil);
                                $nama = $baris[3];
                                $email = $baris[4];
                                $tanggal = $baris[5];
                                $hakakses_ = $baris[7];
                                if ($hakakses_ == 0){
                                    $hakakses = "Only me";
                                }
                                else if ($hakakses_ == 1){
                                    $hakakses = "Follower Only";
                                }
                                else if ($hakakses_ == 2){
                                    $hakakses = "Anyone in Foo-Too";
                                }
                                else if ($hakakses_ == 3){
                                    $hakakses = "Everybody";
                                }
                            }
						?>
                            <div>
                                <label>Nama</label>
                                <input type="text" value="<?php echo $nama;?>" id = "nama" name="nama" onblur="hehehe()"/>
                                <div id = "validasi_nama"><br/></div>
                            </div>
                            <div>
                                <label>Password</label>
                                <input type="password" value="" id = "password" name="password" onblur="hehehe()"/>
                                <div id = "validasi_pass"><br/></div>
                            </div>
                            <div>
                                <label>Password Lagi</label>
                                <input type="password" value="" id = "passwordAgain" onblur="hehehe()"/>
                                <div id = "validasi_pass2"><br/></div>
                            </div>
                            <div>
                                <label>Email</label>
                                <input type="text" value="<?php echo $email; ?>" id = "email" name="email" onblur="hehehe()"/>
                                <div id = "validasi_email"><br/></div>
                            </div>
                            <div>
                                <label>Hak akses</label>
                                <select id = "hakakses" name="hakakses" onblur="hehehe()">
                                    <?php
                                        if ($hakakses_ == 0){
                                          echo '<option value="0" SELECTED>Only Me</option>';
                                          echo '<option value="1">Follower Only</option>';
                                          echo '<option value="2">Anyone in Foo-too</option>';
                                          echo '<option value="3">Everybody</option>';
                                        }

                                        else if ($hakakses_ == 1){
                                          echo '<option value="0">Only Me</option>';
                                          echo '<option value="1" SELECTED>Follower Only</option>';
                                          echo '<option value="2">Anyone in Foo-too</option>';
                                          echo '<option value="3">Everybody</option>';
                                        }

                                        else if ($hakakses_ == 2){
                                          echo '<option value="0">Only Me</option>';
                                          echo '<option value="1">Follower Only</option>';
                                          echo '<option value="2" SELECTED>Anyone in Foo-too</option>';
                                          echo '<option value="3">Everybody</option>';
                                        }

                                        else if ($hakakses_ == 3){
                                          echo '<option value="0">Only Me</option>';
                                          echo '<option value="1">Follower Only</option>';
                                          echo '<option value="2">Anyone in Foo-too</option>';
                                          echo '<option value="3" SELECTED>Everybody</option>';
                                        }

                                    ?>
                                </select>
                                <div id = "validasi_email"><br/></div>
                            </div>
                            <div>
                                <label>Tanggal Lahir</label>
                                <input type="text" value="<?php echo $tanggal; ?>" size="25" id = "tanggalLahir" name="lahir" onblur="hehehe()"/>
                                <a href="javascript:NewCal('."'tanggalLahir','yyyymmdd'".')">
                                   <img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/>
                                </a>
                                <div id = "validasi_tgl"><br/></div>
                            </div>
                        
                    <?php
                        $user = getUserNamePage();
                    ?>
                    <!--
                    <div>
                        <button style="margin-left: 450px;" id = "submit" onmouseover="validasi()">Submit</button>
                    </div>
                    -->
                    <br/>
                    <div style="margin-left: 350px;" class="button180" onclick="backToProfile('<?php echo $user; ?>')">Cancel</div>
                    <br/>
                    <div style="margin-left: 350px;" class="button180" onclick="submiteditform()" onmouseover="validasi()">Submit</div>
                </div>
            </form>
        </div>
    </div>
    <div id="footerwrapper">
    	<div id="footer">
            <div id="footerleft"><br/>
            	ft, ft logoes are trademark of ft company. <br/>
            	Copyright 2010 by : <br/>
                13508011 - M. Albadr Lutan Nasution <br/>
                13508019 - Gregorius Ronny Kaluge <br/>
                13508099 - Alwi Alfiansyah Ramdan <br/>
            </div>
            <div id="footermiddle">

            </div>
            <div id="footerright">

            </div>
        </div>
    </div>
</body>
</html>


